﻿#include "setup7wind.h"
#include "ui_setup7wind.h"
#include <mainwindow.h>
#include "mainwindow.h"
extern intListener doorStatus;
setup7wind::setup7wind(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::setup7wind)
{
    ui->setupUi(this);
    connect(&doorStatus, &intListener::valueChanged,this,&setup7wind::doorStatusChanged,Qt::QueuedConnection);
#ifdef Q_OS_ANDROID
    int fontId = QFontDatabase::addApplicationFont(":/FontStyle/AlibabaPuHuiTi-3-55-Regular.ttf");
    if (fontId != -1) {
        QStringList fontFamilies = QFontDatabase::applicationFontFamilies(fontId);
        if (!fontFamilies.isEmpty()) {
            QString familyName = fontFamilies.first();
            QFont font(familyName, 18); // 创建一个QFont对象，设置字体名称和默认大小

            // 使用setFont方法设置字体，传入QFont对象
            ui->label->setFont(font);
            ui->label_2->setFont(font);
            ui->comboBox->setFont(font);
            ui->comboBox_2->setFont(font);
            ui->SaveBtn->setFont(font);
            ui->SaveBtn_2->setFont(font);


            // 如果需要为其他按钮设置不同的大小，可以创建新的QFont对象
            QFont smallerFont(familyName, 16);
            ui->returnBtn->setFont(familyName);
            ui->pushButton_9->setFont(familyName);
        }
    }
#endif
}
void setup7wind::doorStatusChanged(){
    if(doorStatus.get()==0)
    {
        ui->pushButton_9->setText("        打开仓门");
    }
    else
    {
        ui->pushButton_9->setText("        关闭仓门");
    }
}
setup7wind::~setup7wind()
{
    delete ui;
}
void setup7wind::showEvent(QShowEvent *event)
{
    tcpClient = TcpClient::getInstance();
    if(doorStatus.get()==0)
    {
        ui->pushButton_9->setText("        打开仓门");
    }
    else
    {
        ui->pushButton_9->setText("        关闭仓门");
    }
    event->accept();
}
void setup7wind::on_returnBtn_clicked()
{
    this->close();
    emit changeTotalWindow();
}


void setup7wind::on_SaveBtn_2_clicked()
{
    this->close();
    emit changeTotalWindow();
}


void setup7wind::on_pushButton_9_clicked()
{
    if(doorStatus.get()==0)
    {
        doorStatus.set(1);
        ui->pushButton_9->setText("        关闭仓门");
    }
    else
    {
        doorStatus.set(0);
        ui->pushButton_9->setText("        打开仓门");
    }
}


void setup7wind::on_comboBox_2_currentTextChanged(const QString &arg1)
{
//    if(arg1=="打开"){
//        MainWindow::speechflagkg.set(0);
//        qDebug()<<"打开串口";
//    }else if(arg1=="关闭"){
//        MainWindow::speechflagkg.set(1);
//        qDebug()<<"关闭串口";
//    }
}

void setup7wind::on_SaveBtn_clicked()
{
//    qDebug()<<ui->comboBox_2->currentText();
    if(ui->comboBox_2->currentText()=="打开"){
        MainWindow::speechflagkg.set(0);
        qDebug()<<"打开串口";
    }else if(ui->comboBox_2->currentText()=="关闭"){
        MainWindow::speechflagkg.set(1);
        qDebug()<<"关闭串口";
        qDebug()<<MainWindow::speechflagkg.get();
    }
    QMessageBox::information(nullptr, "提示", "保存成功");

}
